﻿using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using VehicleRental.WpfClient.Behavior;
using VehicleRental.WpfClient.Data;
using VehicleRental.WpfClient.Helpers;
using VehicleRental.WpfClient.Models;
using VehicleRental.Models;

namespace VehicleRental.WpfClient.ViewModels
{
    public class PrivateVehicleViewModel
    {
        private ICommand rentCar;

        private ICommand returnCar;

        public string Manufacturer { get; set; }

        public string Model { get; set; }

        public VehicleType Type { get; set; }

        public int Year { get; set; }

        public string ImageSource { get; set; }

        public decimal PricePerHours { get; set; }

        public decimal Fee { get; set; }

        public int Id { get; set; }

        public int PlaceId { get; set; }

        public int RentPeriod { get; set; }

        public bool IsNotRented
        {
            get
            {
                return !(this.IsRented);
            }
        }

        public ICommand RentCar
        {
            get
            {
                if (this.rentCar == null)
                {
                    this.rentCar = new RelayCommand(this.HandleRentCar);
                }

                return this.rentCar;
            }
        }

        private void HandleRentCar(object parameter)
        {
            RentCarModel currentCar = new RentCarModel()
            {
                PlaceId = this.PlaceId,
                RentPeriod = this.RentPeriod,
                VehicleId = this.Id
            };

            DataPersister.RentCar(currentCar);
        }

        public bool IsRented { get; set; }
    }
}
